//
//  BaseTabBarController.h
//  Rongniu
//
//  Created by Apple on 16/2/22.
//  Copyright © 2016年 Fangwei. All rights reserved.
//

#import "FWNetTool.h"
#import "AFNetworking.h"
#import "FWFarmData.h"
#define BASEURL  @"http://120.27.141.216//zxphp/index.php/front/"//线上环境
//#define BASEURL @"http://127.0.0.1:8888//zxphp/index.php/front/"//线下环境

@implementation FWNetTool


+ (void)postWithUrl:(NSString *)url parameters:(NSDictionary *)parameters success:(void (^)(id json))success failure:(void (^)(NSError *error))failure
{

    // 编码

    //（1）获取URL
    url = [BASEURL stringByAppendingString:url];
    NSLog(@"请求地址%@", url);
    
    AFHTTPSessionManager* manager = [AFHTTPSessionManager manager];
    
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    manager.securityPolicy.allowInvalidCertificates = YES;
    
    [manager POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        if (success) {
            id resultX = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
            success(resultX);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (failure) {
            
            failure(error);
        }
    }];

    


}



//+ (void)postWithUrl:(NSString *)url parameters:(NSDictionary *)parameters farmDatas:(NSArray *)farmDatas success:(void (^)(id json))success failure:(void (^)(NSError *error))failure
//{
//
//    
//    //（1）获取URL
//    url = [BASEURL stringByAppendingString:url];
//    
//    // 1.创建请求管理对象
//    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    //告诉管理对象响应的数据为JSON
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
//    
//
//     // 2.发送请求
//        [manager POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { // 在发送请求之前调用这个block
//            // 必须在这里说明要上传哪些文件
//
//            for (FWFarmData *data in farmDatas) {
//                [formData appendPartWithFileData:data.data name:data.name fileName:data.fileName mimeType:data.mimeType];
//            }
//
//        } success:^(NSURLSessionDataTask *operation, id responseObject) {
//
//            if (success) {
//                success(responseObject);
//            }
//
//        } failure:^(NSURLSessionDataTask *operation, NSError *error) {
//
//            if (failure) {
//                failure(error);
//            }
//
//        }];
//
//}


@end
